import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import mapper.CarMapper;
import pojo.Car;
import utils.SqlSessionUtil;

import java.util.List;

public class mappertest {
    @Test
    public void test1() throws Exception
    {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CarMapper mapper = sqlSession.getMapper(CarMapper.class);
        Car car = mapper.SelectById(1L);
        System.out.println(car);
    }
    @Test
    public void test2() throws Exception
    {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CarMapper mapper = sqlSession.getMapper(CarMapper.class);
        List<Car> carList = mapper.SelectAll("asc");
        carList.forEach( car -> System.out.println(car));

    }
    @Test
    public void test3() throws Exception{
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CarMapper mapper = sqlSession.getMapper(CarMapper.class);
        int result = mapper.DeleteBatch("1,2,3");
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void test4() throws Exception{
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CarMapper mapper = sqlSession.getMapper(CarMapper.class);
        List<Car> carList = mapper.SelectBytype("能源");
        carList.forEach( car -> System.out.println(car));
    }
    @Test
    public void test5() throws Exception{
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CarMapper mapper = sqlSession.getMapper(CarMapper.class);
        Car car = new Car(null,"京A12345","五菱",1000.0,"2020-01-01","新能源");
        mapper.insertCar(car);
        System.out.println( car);
        sqlSession.commit();
        sqlSession.close();
    }
}
